import SwiftUI

struct AnimatableAttributes_Opacity : View {
    @State var isShow: Bool = true // 是否显示蓝色方块
    
    var body: some View {
        VStack(spacing: 30) {
            Text("Animatable Attributes")
                .font(.largeTitle)
            
            Text("Opacity")
                .font(.title)
                .foregroundColor(.gray)
            
            Text("Opacity is the quality of thickness, solidness or opaqueness. The more opacity, the more solid something appears.")
                .font(.title3)
                .padding()
                .frame(maxWidth: .infinity)
                .background(
                    Color.indigo
                )
            
            makeDemoView()
            
            Spacer()
            
            Button(action: {
                isShow.toggle()
            }, label: {
                Text(isShow ? "Hide" : "Show")
            })
            .padding(.bottom, 50)
            .font(.title)
        }
    }
    
    func makeDemoView() -> some View {
        RoundedRectangle(cornerRadius: 16)
            .foregroundColor(.blue)
            .padding()
            .opacity(isShow ? 1 : 0) // 不透明度
            .animation(.easeInOut, value: isShow)
    }
}
